<?php
class Admin_model extends CI_Model {
	function importfromxml($upload_data)
	{	
		$data = simplexml_load_file($upload_data['full_path']);
		
		$this->db->truncate('Obsahuje');
		$this->db->truncate('Vyber');
		$this->db->truncate('Jedlo'); 
		foreach ($data->jedlo as $row) {
			$query = $this->db->where('ID', $row->ID)->get('Jedlo');
			if ($query->num_rows() == 0) {			
				$table_jedlo = array(
					'ID' => $row->ID,
					'Nazov_jedla' => "$row->Nazov_jedla",
					'Hmotnost' => $row->Hmotnost,
					'Vyzivova_hmota' => $row->Vyzivova_hmota
				);
				$this->db->insert('Jedlo', $table_jedlo);
			}
			$this->dieta_model->pridanie_ingrediencii("$row->Nazov");
			$table_obsahuje = array(
				'Nazov_jedla' => $row->ID,
				'Nazov' => "$row->Nazov"
			);
			$this->db->insert('Obsahuje', $table_obsahuje);
		}
	}
}